//
//  TimeTopView.m
//  XinLiJianKangJiaoYu
//
//  Created by 李文强 on 2018/12/19.
//  Copyright © 2018 sijiaokeji. All rights reserved.
//

#import "TimeTopView.h"

@implementation TimeTopView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        [self initSubView];
        [self initOption];
        [self layout];
    }
    return self;
}
- (void)initSubView{
    [self addSubview:self.centerLabel];
    [self addSubview:self.leftButton];
    [self addSubview:self.rightButton];
}
- (void)initOption{
    self.backgroundColor = [UIColor whiteColor];
}
- (void)layout{
    [_centerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@120);
        make.height.equalTo(@20);
    }];
    [_leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.width.equalTo(@60);
        make.centerY.equalTo(self.mas_centerY);
        make.height.equalTo(@20);
    }];
    [_rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@0).offset(-10);
        make.width.equalTo(@60);
        make.centerY.equalTo(self.mas_centerY);
        make.height.equalTo(@20);
    }];
}
- (void)leftClick:(UIButton *)sender{
    [self.delegate getPrevious];
}
- (void)rightClick:(UIButton *)sender{
    [self.delegate getNext];
}
- (void)drawRect:(CGRect)rect{
    UIBezierPath *path = [[UIBezierPath alloc]init];
    [path moveToPoint:CGPointMake(0, 59)];
    [path addLineToPoint:CGPointMake(APP_WIDTH-20, 59)];
    [BACKLINECOLOR set];
    [path stroke];
}
- (UIButton *)leftButton{
    if (!_leftButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"上一月" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(leftClick:) forControlEvents:UIControlEventTouchUpInside];
        _leftButton = button;
    }
    return _leftButton;
}
- (UIButton *)rightButton{
    if (!_rightButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"下一月" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(rightClick:) forControlEvents:UIControlEventTouchUpInside];
        _rightButton = button;
    }
    return _rightButton;
}
- (UILabel *)centerLabel{
    if (!_centerLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.textColor = [UIColor darkGrayColor];
        label.font = [UIFont systemFontOfSize:20];
        label.textAlignment = 1;
        _centerLabel = label;
    }
    return _centerLabel;
}

@end
